package com.huawei.appmarket.service.webview;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.webkit.WebView;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appmarket.service.reserve.game.bean.WarmUpPageInfo;
import com.huawei.appmarket.service.webview.base.jssdk.control.FullAppStatus;
import com.huawei.appmarket.service.webview.base.jssdk.nativemessage.DownloadProgressNativeMsg;
import com.huawei.appmarket.service.webview.base.jssdk.nativemessage.PayChangeNativeMsg;
import com.huawei.appmarket.service.webview.base.jssdk.nativemessage.ShareResultNativeMessage;
import com.huawei.hwCloudJs.JsClientApi;
import com.huawei.hwCloudJs.service.jsmsg.NativeMsg;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.azb;
import o.azj;
import o.azm;
import o.cjk;
import o.cjm;
import o.cjo;
import o.Logger;
import o.ContentManager;
import o.dvq;
import o.ebz;
import o.eew;
import o.efm;
import o.end;
import o.enf;
import o.ewm.h;
import o.ewm.j;
import o.fho;
import o.ll;

public class WiseDistWebViewImpl implements azm {
    private String ʻ;
    private final BroadcastReceiver ʼ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ WiseDistWebViewImpl ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (dvq.ˊ().equals(intent.getAction()) && !TextUtils.isEmpty(this.ˊ.ᐝ) && this.ˊ.ˊ != null) {
                WarmUpPageInfo ˏ = efm.ˏ().ˏ(this.ˊ.ᐝ);
                if (ˏ != null) {
                    this.ˊ.ˏ(ˏ, false);
                }
            }
        }
    };
    private eew ʽ;
    private LinearLayout ˊ;
    private String ˋ;
    private boolean ˎ = false;
    private BroadcastReceiver ˏ = new a();
    private e ॱ = new e();
    private end ॱॱ = new b();
    private String ᐝ;

    static class a extends BroadcastReceiver {
        private a() {
        }

        public void onReceive(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            NativeMsg payChangeNativeMsg = new PayChangeNativeMsg();
            payChangeNativeMsg.setPkgs(safeIntent.getStringArrayListExtra("payDataChange"));
            JsClientApi.notifyNativeMsg(payChangeNativeMsg);
        }
    }

    static class b implements end {
        private b() {
        }

        public void ॱ(FullAppStatus fullAppStatus) {
            NativeMsg downloadProgressNativeMsg = new DownloadProgressNativeMsg();
            downloadProgressNativeMsg.setPackageName(fullAppStatus.ˎ());
            downloadProgressNativeMsg.setAppType(fullAppStatus.appType_);
            downloadProgressNativeMsg.setStatus(fullAppStatus.ˋ());
            downloadProgressNativeMsg.setProgress(fullAppStatus.ˊ());
            JsClientApi.notifyNativeMsg(downloadProgressNativeMsg);
        }
    }

    static class e extends BroadcastReceiver {
        private e() {
        }

        public void onReceive(Context context, Intent intent) {
            int intExtra = new SafeIntent(intent).getIntExtra("share_status_key", 1);
            if (intExtra == 0) {
                Logger.ˏ("WisDistWebViewImpl", "notify share success");
                NativeMsg shareResultNativeMessage = new ShareResultNativeMessage();
                shareResultNativeMessage.setStatus(intExtra);
                JsClientApi.notifyNativeMsg(shareResultNativeMessage);
            }
        }
    }

    protected void ˊ(String str) {
        this.ᐝ = str;
    }

    private void ˎ(String str) {
        this.ʻ = str;
    }

    public void ॱ(Context context) {
        ˋ(context);
        ˊ();
        ˋ();
    }

    public LinearLayout ˎ(Context context, LinearLayout linearLayout) {
        this.ˊ = (LinearLayout) LayoutInflater.from(context).inflate(h.ʻʼ, linearLayout);
        azb.ˏ(this.ˊ, j.ﾞʻ);
        return this.ˊ;
    }

    public void ॱ(Context context, WebView webView, String str, String str2, Handler handler) {
        ˊ(str);
        ˎ(str2);
        WarmUpPageInfo ˏ = efm.ˏ().ˏ(str);
        if (ˏ != null) {
            if (!this.ˎ) {
                ॱ(context, handler, webView);
                this.ˎ = true;
            }
            ˏ(ˏ, true);
        }
    }

    public void ˊ(Context context, String str, Handler handler) {
        ˊ(str);
    }

    public boolean ˎ(Context context, WebView webView, String str) {
        if (ˋ(context, str)) {
            return true;
        }
        return false;
    }

    public void ॱ(Context context, String str) {
        if (!TextUtils.isEmpty(str)) {
            this.ˋ = str;
            enf.ˋ().ˎ(str, this.ॱॱ);
        }
    }

    public void ˊ(Context context) {
        ˎ(context);
        ॱ();
        ˎ();
        if (!TextUtils.isEmpty(this.ˋ)) {
            enf.ˋ().ˊ(this.ˋ);
        }
    }

    private void ˋ(Context context) {
        context.registerReceiver(this.ʼ, new IntentFilter(dvq.ˊ()), dvq.ॱ(), null);
    }

    private void ˎ(Context context) {
        try {
            context.unregisterReceiver(this.ʼ);
        } catch (Exception e) {
            Logger.ˋ("WisDistWebViewImpl", "unregisterReceiver fail:" + e.toString());
        }
        if (this.ʽ != null) {
            this.ʽ.ˊ();
            this.ʽ.ॱ();
            this.ʽ.ˎ();
        }
    }

    private void ॱ(Context context, Handler handler, WebView webView) {
        this.ʽ = new eew(context, handler, webView);
        this.ʽ.ˏ(this.ˊ);
    }

    private void ˏ(WarmUpPageInfo warmUpPageInfo, boolean z) {
        if (this.ʽ != null) {
            this.ʽ.ˊ(warmUpPageInfo, z, this.ʻ);
        }
    }

    public boolean ˋ(Context context, String str) {
        if (((azj) fho.ˏ().ˋ("AGWebView").ॱ(azj.class)).ॱ(str)) {
            int indexOf = str.indexOf("?");
            if (indexOf > 0) {
                str = str.substring(0, indexOf);
            }
            String ˋ = ˋ(str);
            if (ˋ != null) {
                try {
                    cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
                    appDetailActivityProtocol.ˏ(new Request(ˋ, null));
                    cjk.ˎ().ˋ(context, new cjm("appdetail.activity", appDetailActivityProtocol));
                    return true;
                } catch (Throwable e) {
                    Logger.ˋ("WisDistWebViewImpl", "gotoAppDetail error", e);
                }
            }
        }
        return false;
    }

    public void ˊ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ebz.ॱ);
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.ˏ, intentFilter);
    }

    public void ॱ() {
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ˏ);
    }

    private void ˋ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("share_result_broadcast");
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.ॱ, intentFilter);
    }

    private void ˎ() {
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ॱ);
    }

    private String ˋ(String str) {
        int lastIndexOf = str.lastIndexOf("/") + 1;
        if (lastIndexOf <= 0 || str.length() <= lastIndexOf) {
            return null;
        }
        return "app|" + str.substring(lastIndexOf);
    }
}
